﻿@{
    ViewBag.Title = "维修明细";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section scripts{
    <script src="~/Areas/Dev/ViewModels/Dev.com.js"></script>
    <script src="~/Areas/Dev/ViewModels/Dev.viewModel.edit.js"></script>
    <script type="text/javascript">
            using(['numberbox','lookup','combobox']);
            var viewModel = function(){
                var self = this;
                Dev.viewModel.edit.apply(self,arguments);
                this.grid.size={w:6,h:151};
                this.grid.OnAfterCreateEditor = function(editors,row){
                };
                this.grid.OnBeforeDestroyEditor = function (editors, row) {
                row.Wxjlmx_Wxxm = editors["Wxjlmx_Wxxm"].target.lookup('textbox').val();
                row.Wxjlmx_Fzry = editors["Wxjlmx_Fzry"].target.lookup('textbox').val();
                row.Wxjlmx_Jcry = editors["Wxjlmx_Jcry"].target.lookup('textbox').val();
                };
                 this.saveClick = function () {
                    //保存主表及明细表
                    var bmmc=$("#Wxjl_Bmbh").combobox('getText');
                    self.form["Wxjl_Bmmc"]=bmmc;
                    if (self.readonly()) return;
                    self.gridEdit.ended(); //结束grid编辑状态
                    var post = {           //传递到后台的数据
                        form: com.formChanges(self.form, data.form, self.setting.postFormKeys),
                        list: self.gridEdit.getChanges(self.setting.postListFields)
                    };
                    if ((self.gridEdit.ended() && com.formValidate()) && (post.form._changed || post.list._changed)) {
                        com.ajax({
                            url: self.urls.edit,
                            data: ko.toJSON(post),
                            success: function (d) {
                                com.message('success', self.resx.editSuccess);
                                ko.mapping.fromJS(post.form, {}, data.form); //更新旧值
                                self.gridEdit.accept();
                            }
                        });
                    }

                    };
                this.addRowClick = function(){
                        if (self.readonly()) return;
                        var sBillNo = this.scrollKeys.current();
                        //获取RowId 与单据编号
                        com.ajax({
                            type: 'GET',
                            url: this.urls.getrowid + 1,
                            data: { BillNo: sBillNo },
                            success: function (d) {
                                var row = $.extend({ Wxjlmx_BillNo: sBillNo, Wxjlmx_Flbh: d }, self.defaultRow);
                                self.gridEdit.addnew(row);
                            }
                        });

              };  
            };
            var data = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
            ko.bindingViewModel(new viewModel(data));
    </script>
    }

<div class="z-toolbar">
    <a id="a_save" href="#" plain="true" class="easyui-linkbutton" icon="icon-save" data-bind="click:saveClick,linkbuttonDisable:readonly" title="保存">保存</a>
    <a id="a_undo" href="#" plain="true" class="easyui-linkbutton" icon="icon-undo" data-bind="click:rejectClick,linkbuttonDisable:readonly" title="撤消">撤消</a>
    <a id="a_audit" href="#" plain="true" class="easyui-linkbutton" icon="icon-user-accept" data-bind="click:auditClick,easyuiLinkbutton:approveButton" title="审核">审核</a>
    <a id="a_printer" href="#" plain="true" class="easyui-linkbutton" icon="icon-printer" title="打印" data-bind="click:printClick">打印</a>
    <div class="datagrid-btn-separator"></div>
    <a id="a_first" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_first" data-bind="click:firstClick,linkbuttonEnable:scrollKeys.firstEnable" title="第一条"></a> 
    <a id="a_previous" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_previous" data-bind="click:previousClick,linkbuttonEnable:scrollKeys.previousEnable" title="上一条"></a> 
    <a id="a_next" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_next" data-bind="click:nextClick,linkbuttonEnable:scrollKeys.nextEnable" title="下一条"></a> 
    <a id="a_last" href="#" plain="true" class="easyui-linkbutton" icon="icon-resultset_last" data-bind="click:lastClick,linkbuttonEnable:scrollKeys.lastEnable" title="最后一条"></a> 
</div>

<div id="master" class="container_12" data-bind="inputwidth:0.9">
    <div class="grid_1 lbl">单据编号</div>
    <div class="grid_3 val"><input type="text" id="Wxjl_BillNo" name="Wxjl_BillNo"  data-bind="value:form.Wxjl_BillNo,readOnly:true" class="z-txt readonly"/></div>
    <div class="grid_1 lbl required">设备名称</div>
    <div class="grid_3 val"><input type="text"  data-bind="lookupValue:form.Wxjl_Sbbh,lookupReadOnly:readonly" required="true" class="z-txt easyui-lookup" data-options="lookupType:'sbda',multiple:false"/></div>
    <div class="grid_1 lbl required">维修部门</div>
    <div class="grid_3 val"><input type="text" id="Wxjl_Bmbh" data-bind="lookupValue:form.Wxjl_Bmbh,lookupReadOnly:readonly" required="true" class="z-txt easyui-lookup" data-options="lookupType:'organize',multiple:false" /></div>
    <div class="clear"></div> 
               

    <div class="grid_1 lbl required">维修人员</div>
    <div class="grid_3 val required"><input type="text" id="Wxjl_Wxry" data-bind="lookupValue:form.Wxjl_Wxry,lookupReadOnly:readonly"  required="true"  class="z-txt easyui-lookup" data-options="lookupType:'sysuser',multiple:false" /></div>
    <div class="grid_1 lbl required">开始时间 </div>
    <div class="grid_3 val required"><input type="text" data-bind="dateboxValue:form.Wxjl_Kssj,dateboxReadOnly:readonly" class="z-txt easyui-datebox"  /></div>


    <div class="grid_1 lbl required">结束时间</div>
    <div class="grid_3 val required"><input type="text" data-bind="dateboxValue:form.Wxjl_Jssj,dateboxReadOnly:readonly" class="z-txt easyui-datebox"  /></div>
    <div class="clear"></div>


    <div class="grid_1 lbl ">维修工时 </div>
    <div class="grid_3 val "><input type="text" data-bind="numberboxValue:form.Wxjl_Wxgs" class="z-txt easyui-numberbox "  /></div>
    <div class="grid_1 lbl">停机工时 </div>
    <div class="grid_3 val "><input type="text" data-bind="numberboxValue:form.Wxjl_Tjgs" class="z-txt easyui-numberbox" /></div>
    <div class="grid_1 lbl">维修费用 </div>
    <div class="grid_3 val "><input type="text" data-bind="numberboxValue:form.Wxjl_Wxfy" class="z-txt easyui-numberbox" /></div>
    <div class="clear"></div>


    <div class="grid_1 lbl">维修内容 </div>
    <div class="grid_3 val "><input type="text" data-bind="value:form.Wxjl_Wxnr,readOnly:readonly" class="z-txt"  /></div>
    <div class="grid_1 lbl">维修人数 </div>
    <div class="grid_3 val "><input type="text" data-bind="value:form.Wxjl_Wxrs,readOnly:readonly" class="z-txt"  /></div>
    <div class="grid_1 lbl">具体要求 </div>
    <div class="grid_3 val "><input type="text" data-bind="value:form.Wxjl_Tjyq,readOnly:readonly" class="z-txt"  /></div>
    <div class="clear"></div>


    <div class="grid_1 lbl">备注说明 </div>
    <div class="grid_3 val"><input type="text" data-bind="value:form.Wxjl_Remark,readOnly:readonly" class="z-txt"  /></div>
    <div class="clear"></div>
</div>
  
<div id="tt" class="easyui-tabs">  
    <div title="表单明细">
        <table id="list" data-bind="datagrid:grid">
            <thead>
                <tr>
                    <th field="Wxjlmx_BillNo" hidden="true"></th>  
                    <th field="Wxjlmx_Flbh"   hidden="false"  >分录编号</th> 
                    <th field="Wxjlmx_Wxxm"   align="left"    width="150" editor="{type:'lookup',options:{lookupType:'sbwxxm',parentField:'pid'}}" >维修项目 </th> 
                         
                    <th field="Wxjlmx_Wxyq"   align="left"    width="150" editor="text" >维修要求 </th>   
                    <th field="Wxjlmx_Fzry"   align="left"    width="80"  editor="{type:'lookup',options:{lookupType:'sysuser',parentField:'pid'}}" >负责人员   </th>  
                    <th field="Wxjlmx_Jcry"   align="left"    width="80" editor="{type:'lookup',options:{lookupType:'sysuser',parentField:'pid'}}" >检查人员   </th>    
                    <th field="Wxjlmx_Remark"  align="left"    width="150" editor="text" >备注说明 </th> 
                          
                    <th field="CreatePerson"  sortable="true" align="center"  width="70"   >创建人</th>  
                    <th field="CreateDate"    sortable="true" align="center"  formatter="com.formatDate"    width="100" >创建日期</th>   
                </tr>
            </thead>
        </table>  
            
        <div id="gridtb">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" data-bind="click:addRowClick,linkbuttonDisable:readonly">增加明细</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" data-bind="click:removeRowClick,linkbuttonDisable:readonly">删除明细</a>
        </div>  
    </div>
    <div title="表单信息" class="hide" style="padding-top:2px;">
        <div class="container_12" id="BillDetail" data-bind="inputwidth:0.9,autoheight:181"> 
            <div class="clear"></div>
            <div class="grid_1 lbl">审批状态</div>
            <div class="grid_3 val"><input type="text" id="ApproveState" data-bind="value:form.ApproveState,readOnly:true" class="z-txt readonly"/></div>
            <div class="grid_1 lbl">审批意见</div>
            <div class="grid_3 val"><input type="text" id="ApproveRemark" data-bind="value:form.ApproveRemark,readOnly:true"  class="z-txt readonly"/></div>
            <div class="grid_1 lbl">审批人 </div>
            <div class="grid_3 val"><input type="text" id="ApprovePerson"data-bind="value:form.ApprovePerson,readOnly:true" class="z-txt readonly"/></div>

            <div class="clear"></div>
            <div class="grid_1 lbl">审批日期</div>
            <div class="grid_3 val"><input type="text" id="ApproveDate" data-bind="dateboxValue:form.ApproveDate,dateboxReadOnly:true"  class="z-txt easyui-datebox readonly"/></div>
            <div class="grid_1 lbl">编制日期</div>
            <div class="grid_3 val"><input type="text" id="CreateDate" data-bind="dateboxValue:form.CreateDate,dateboxReadOnly:true" class="z-txt easyui-datebox readonly" /></div>
            <div class="grid_1 lbl">编制人</div>
            <div class="grid_3 val "><input type="text" id="CreatePerson" data-bind="value:form.CreatePerson,readOnly:true" class="z-txt readonly" /></div>
                
            <div class="clear"></div>
            <div class="grid_1 lbl">修改日期</div>
            <div class="grid_3 val"><input type="text" id="UpdateDate" data-bind="dateboxValue:form.UpdateDate,dateboxReadOnly:true" class="z-txt easyui-datebox readonly" /></div>
            <div class="grid_1 lbl">修改人</div>
            <div class="grid_3 val "><input type="text" id="UpdatePerson" data-bind="value:form.UpdatePerson,readOnly:true" class="z-txt readonly" /></div>
        </div>
    </div> 
</div>  
